<template>
    <div>
        <div v-if="append==false && create==false && config==false">
            <el-header style="box-shadow: rgba(0, 0, 0, 0.05) 0px 2px 20px 0.5px;border-radius:6px;padding:20px;height:56px">
          <div class="flexBox" >
              <el-breadcrumb separator="/">
                  <el-breadcrumb-item :to="{ path: '/home' }"
                  >首页</el-breadcrumb-item>
                  <el-breadcrumb-item>人事调动</el-breadcrumb-item>
                  <el-breadcrumb-item>转科管理</el-breadcrumb-item>
              </el-breadcrumb>
          </div>
        </el-header >
        <el-main style="box-shadow: rgba(0, 0, 0, 0.05) 0px 2px 20px 0.5px;border-radius:6px;padding:20px;margin-top:20px">
            <el-form :inline="true" :model="formInline" class="demo-form-inline" ref="searchForm">
                <el-form-item label="检索输入">
                    <el-input v-model="formInline.name" placeholder="请输入姓名 / 档案号 / 工号" size="small"></el-input>
                </el-form-item>
                <el-form-item label="选择科室">
                    <el-select v-model="formInline.dept" placeholder="请选择科室" size="small">
                        <el-option label="护理部" value="shanghai"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="人员类别">
                    <el-select v-model="formInline.type" placeholder="请选择人员类别" size="small">
                        <el-option label="医生" value="shanghai"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="档案年份">
                    <el-date-picker size="small" type="year" value-format="yyyy" v-model="formInline.dataTime"></el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit('submit')" size="mini">查询</el-button>
                    <el-button  @click="onSubmit('reset')" size="mini">重置</el-button>
                </el-form-item>
            </el-form>
            <el-divider></el-divider>
            <el-button type="primary" style="float:left;margin-bottom:10px" @click="handleCreate" size="mini">新增转科</el-button>
             <el-table
                v-loading="showTable"
                :data="tableData"
                border
                style="width: 100%;margin-top:20px"
                :header-cell-style="{ background: 'rgb(245,247,250)' }"
                >
                <el-table-column
                  prop="name"
                  label="姓名"
                  align="center"
                  width="180"
                  fixed="left">
                </el-table-column>
                <el-table-column
                  v-for="item in year"
                  :label="now+'年'+item+'月'"
                  align="center"
                  width="180">
                    <template slot-scope="scope">{{ scope.row.arr[item-1].deptNames }}</template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  align="center"
                  fixed="right"
                  width="180">
                    <template slot-scope="scope">
                        <el-button
                        size="mini"
                        type="text"
                        @click="handleConfig(scope.row)">编辑</el-button>
                        <el-button
                        size="mini"
                        type="text"
                        @click="handleAppend(scope.row)">追加计划</el-button>
                    </template>
                </el-table-column>
              </el-table>
        </el-main>
        </div>
        <div v-else>
<!--            <appendTurn v-if="append==true" @cancle="appendCancle"></appendTurn>-->
<!--            <newTurn v-if="create==true" @cancle="createCancle"></newTurn>-->
<!--            <confTurn ref="configChild" v-if="config==true" @cancle="configCancle"></confTurn>-->
        </div>
    </div>
</template>
<script>
import appendTurn from "../components/appendTurn.vue"
import newTurn from "./newTurn.vue"
// import confTurn from "./confTurn.vue"
import TaskManager from '../service/TaskManager'
export default {
    name:'myTrans',
    components:{appendTurn,newTurn},
    data(){
        return{
            configData:{
              id:'',
              name:'',
              dept:'',
              dict:''
            },
            showTable:false,
            now:"",
            append:false,
            create:false,
            config:false,
            formInline: {
            name: '',
            dept: '',
            type:'',
            dataTime:''
            },
            year:["1","2","3","4","5","6","7","8","9","10","11","12"],
            tableData:[
                {name:"张三",arr:[{deptNames:"信息科"},{deptNames:""},{deptNames:""},{deptNames:"护理部"},{deptNames:"信息科"},{deptNames:"院长办公室"},{deptNames:"信息科"},{deptNames:""},{deptNames:""},{deptNames:"护理部"},{deptNames:"信息科"},{deptNames:"院长办公室"}]},
            ]
        }
    },
    methods:{
      onSubmit(val){
        if(val=='submit'){
          this.now=this.formInline.dataTime;
          console.log(this.now)
          this.getTurnList();
        }else{
          this.$refs.searchForm.resetFields();
        }
      },
      handleAppend(row){
          // this.$router.push({ name: "info", params: { edit: 1, data: row} });
          console.log(row);
          this.$router.push({ name:"newTurn",params:{ from: "追加计划", row: row} });
      },
       handleCreate(){
         this.$router.push({ name:'newTurn',params:{from:"新增计划", row:"" }});
         },
         configLoad(){

         },
         handleConfig(scope){
            console.log(scope);
            window.sessionStorage.turnInfo=JSON.stringify(scope);
            this.$router.push('/confTurn');
        },
        appendCancle(val){
            this.append=val;
        },
        createCancle(val){
            this.create=val;
        },
        configCancle(val){
            this.config=val;
        },
        getTurnList(time){
          this.showTable=true;
          TaskManager.getTurnList().then((res)=>{
            console.log(res.data);
            let data=res.data;
            let table=[];
            for(let key in data){
              table[key] = {
                id: data[key].id,
                name: data[key].name,
                dept: data[key].from,
                arr: [
                  {deptNames:"--"},
                  {deptNames:"--"},
                  {deptNames:"--"},
                  {deptNames:"--"},
                  {deptNames:"--"},
                  {deptNames:"--"},
                  {deptNames:"--"},
                  {deptNames:"--"},
                  {deptNames:"--"},
                  {deptNames:"--"},
                  {deptNames:"--"},
                  {deptNames:"--"}
                ]
              }
              let params={
                name:data[key].name
              }
              TaskManager.getTurnList(params).then((res)=>{
                let _data=res.data;
                for (const dataKey in _data) {
                  let year = _data[dataKey][1].split('-')[0];
                  let mouth = _data[dataKey][1].split('-')[1];
                  if (year == this.now) {
                    table[key].arr[mouth - 1].deptNames = _data[dataKey][0];
                  }
                }
                this.tableData=table;
                this.showTable=false;
              })
            }
          })
        }
    },
    mounted(){
        this.now=new Date().getFullYear();
        this.getTurnList();
    }
}
</script>
<style scoped>
.el-divider{
    margin:  0 0 10px 0;
}
.el-form{
    text-align: left;
}
</style>
